package com.yanqu.road.server.cmd.mall;

import com.yanqu.road.entity.enums.eShopType;
import com.yanqu.road.entity.goods.MallRandomGoods;
import com.yanqu.road.pb.mall.MallProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.mall.MallModule;
import com.yanqu.road.server.manger.activity.assistantcostumemall.AssistantCostumeMallActivityMgr;
import com.yanqu.road.server.manger.config.MallMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_MALL_RANDOM_LIST, desc = "商店随机商品信息")
public class MallRandomGoodsListCmd extends AbstractCommand {

    private int shopType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MallProto.MallRandomGoodsReqMsg reqMsg = MallProto.MallRandomGoodsReqMsg.parseFrom(packet.getBytes());
        shopType = reqMsg.getShopType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        MallRandomGoods mallRandomGoods;
        if (shopType == eShopType.AssistantSkinMall.getValue()) {
            mallRandomGoods = AssistantCostumeMallActivityMgr.getMallRandomGoods();
            player.getModule(MallModule.class).resetAssistantSkinMall(AssistantCostumeMallActivityMgr.getMallRandomGoods());
        } else {
            mallRandomGoods = MallMgr.getMallRandomGoodsByShopType(shopType);
        }
        if (null == mallRandomGoods) {
            ret = GameErrorCode.E_MALL_NO_EXIST;
            return;
        }


        MallProto.MallRandomGoodsRespMsg.Builder respMsg = MallProto.MallRandomGoodsRespMsg.newBuilder();
        MallProto.MallRandomGoodsTemp.Builder mallGoods = MallProto.MallRandomGoodsTemp.newBuilder();
        mallGoods.setShopType(mallRandomGoods.getShopType());
        mallGoods.addAllGoodsList(mallRandomGoods.getMallIdList());
        mallGoods.setLastUpdateTime(mallRandomGoods.getLastUpdateTime());
        respMsg.addRandomGoods(mallGoods);
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_MALL_RANDOM_LIST, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
